<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.beaut.project.util.FlowUtility" %>
<%@ include file="/public/header.jsp"%>
<html>
	<head>
		<title>项目报账管理</title>
	</head>
	<script type="text/javascript">
	$(function(){
		$("#searchValue").keypress(function(e) { 
	    	// 回车键事件 
	     	if(e.which == 13) { 
	     		 doSearch();
	       	} 
	   	}); 
		jQuery("#dept_id").combotree({
			url:'<%=contextPath %>/springMVC/group/listDepartment',
			method:'POST',
			animate:true,
			lines:true,
			onChange:function(){
				doSearch();
			}
		});
		jQuery('#person_id').combogrid({
			title:'人员选择',
			mode:"remote",
			loadMsg:'正在加载数据，请稍后......',
			panelWidth:550,
			panelHeight:400,
			url:"<%=contextPath%>/springMVC/group/listPageUser",
			idField:"id",
			textField:"truename",
			rownumbers:true,
			fitColumns:true,
			columns: [[
				{field:'id',hidden:true},
				{field:'deptId',hidden:true},
				{field:'truename',title:'姓名',width:100},
				{field:'deptName',title:'所属部门',width:100},
				{field:'privName',title:'角色',width:100}
			]],
			toolbar:"#tb",
			pageSize:10,
			pageList:[10,50,100],  
			pagination:true,
			onChange:function(){
				doSearch();
			}
		});
			$("#table").datagrid({
				title:"项目报账管理",
				iconCls:'icon-edit',
				loadMsg:'正在加载数据，请稍后......',
				url:'<%=contextPath %>/springMVC/xmFinance/listPageXMReimbursement?is_borrow=0',
				rownumbers:true,
				fitColumns:true,
				nowrap:false,
				idField:'id',
				frozenColumns:[[
					//{field:'ck',checkbox:true},		
				    {title:'主键',field:'id',hidden:true}
				]],
				columns:[[
					{title:'所属部门',field:'admin_dept',width:100,align:'center'},
					{title:'项目编号',field:'xm_code',width:100,align:'center'},
					{title:'项目名称',field:'xm_name',width:100,align:'center'},
					{title:'报账日期',field:'operation_time',width:150,align:'center'},
					{title:'借款金额',field:'loan_money',width:100,align:'center'},
					{title:'经办人id',field:'creator_id',width:10,hidden:true,align:'center'},
					{title:'经办人',field:'creator',width:100,align:'center'},
					{title:'摘要',field:'remark',width:150,align:'center'},
					{title:'审核状态',field:'status',width:100,align:'center',formatter:function(value,rowData,rowIndex){
						if(value==1){
							return "审核中";
						}else if(value==2){
							return "审核不通过";
						}else if(value==3){
							return "审核通过";
						}
						return "未提交审核";
					}},
					{title:'详情操作',field:'more',width:100,align:'center',formatter:function(value,rowData,rowIndex){
						var str="";
						if(rowData.status == 0 || rowData.status == 2){
							str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-modify' title='编辑' onclick=\"javascript:addOrEditReimbursement(1,'"+rowData.id+"','"+rowData.is_borrow+"');\"/> &nbsp;&nbsp;";
							str+="<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审批' onclick=\"javascript:shenpi(this,'"+rowData.id+"','"+rowData.is_borrow+"');\"/> &nbsp;&nbsp;";
							if(rowData.status == 0){
							str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-no' title='详情' onclick=\"javascript:deleteData('"+rowData.id+"','"+rowData.is_borrow+"');\"/>";
							}
							return str;
						}
						if(rowData.status>0){
							str+="<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-shenpi' title='审核查看' onclick=\"javascript:viewFlowView('"+encodeURIComponent("<%=FlowUtility.XM_BZ_SHENPI%>")+"','"+rowData.id+"');\"/>&nbsp;&nbsp;";
	                    	str+= "<input type='button' style='border:0px #ff0000 solid;width:16px;height:16px;cursor:pointer;' class='icon-details' title='详情' onclick=\"javascript:viewData('"+rowData.id+"','"+rowData.is_borrow+"');\"/>";
						}
	                    return str;
					}}
				]],
				toolbar:"#tb",
				pageSize:10,
				pageList : [10,50,100],  
				pagination:true,
				onLoadSuccess:function(rtJson){
					if(rtJson.rtState== '1')
					{
						$.messager.alert('提示',rtJson.rtMsrg);
					}
				}
			});
		});
        function addOrEditReimbursement(type,id,is_borrow){
		        	if(type==0){
						openDialogResize("<%=contextPath %>/springViews/xm/addOrEditReimbursement.jsp?callback=rtCallBack",1000, 800);
					}else if(type==1){
						openDialogResize("<%=contextPath %>/springViews/xm/addOrEditReimbursement.jsp?callback=rtCallBack&id="+id,1000, 800);
					}else{
						openDialogResize("<%=contextPath %>/springViews/xm/addOrEditReimbursement.jsp?isShow=1&callback=rtCallBack&id="+id,1000, 800);
					}
        }
		function shenpi(obj,id,is_borrow){
	    	//flowBusinessUrl获取审批业务记录的URL(可以是个组合参数字符串),moduleFlow获取工作流程的流程名称
	    	var flowBusinessUrl="";
	    	if(is_borrow==0){
	    		flowBusinessUrl="<%=contextPath %>/springViews/xm/addOrEditReimbursement.jsp?isShow=1&id="+id;
	    	}else{
	    		flowBusinessUrl="<%=contextPath %>/springViews/xm/addOrEditReimbursementByLoan.jsp?isShow=1&id="+id;
	    	}
	      var param="flowBusinessUrl="+encodeURIComponent(flowBusinessUrl)+"&moduleFlow="+encodeURIComponent("<%=FlowUtility.XM_BZ_SHENPI%>")+"&businessId="+id;
	      $(obj).hide();
	      $.ajax({
						type:'POST',
						url:'<%=contextPath %>/springMVC/workFlow/toShenpi',
						dataType:"JSON",
						data:param,
						success:function(rtJson){
							if (rtJson.rtState == '0'){
								openDialogResize(rtJson.rtData.url,1000,800);
							}else{
								warningInfo(rtJson.rtMsrg);
							}
							$(obj).show();
						}
					});
	       
	    } 
		function doSearch()
		{
			var start_time=$('#start_time').datebox('getValue');  
			var end_time=$('#end_time').datebox('getValue');  
			var searchValue = $('#searchValue').val();
			var dept_id = jQuery("#dept_id").combotree('getValue');
			var person_id = jQuery("#person_id").combotree('getValue');
			jQuery('#table').datagrid('load', {
				start_time:start_time,
				end_time:end_time,
				searchValue:searchValue,
				dept_id:dept_id,
				person_id:person_id
			});
		}
		function deleteData(id){
			var rows=$('#table').datagrid('getSelections');
			$.messager.confirm('确认','您确认删除该记录信息？',function(msg){
				if(msg){
					$.ajax({
						type:'POST',
						url:"<%=contextPath %>/springMVC/xmFinance/deleteReimbursement",
						data:"ids="+id,
						success:function(rtJson){
							if(rtJson.rtState == '0'){
								table_reload(rows.length);
							}
							else{
								warningInfo(rtJson.rtMsrg);
							}
						}
					});
				}
			});
		}
		   function deleteRows(){
				var rows=$('#table').datagrid('getSelections');
				var deleteVar="";
				if(rows.length==0)
				{
					$.messager.alert('提示','选中要删除的记录');  
					return ;
				}
				for(var i=0;i<rows.length;i++)
				{
					if(i==(rows.length-1))
					{
						deleteVar+=rows[i].id;
					}else
					{
						deleteVar+=rows[i].id+",";
					}
				}
				$.messager.confirm('确认','您确认删除该记录信息？',function(msg){
					if(msg){
						$.ajax({
							type:'POST',
							url:"<%=contextPath %>/springMVC/xmFinance/deleteReimbursement",
							data:"ids="+deleteVar,
							dataType:"json",
							success:function(rtJson){
								if(rtJson.rtState == '0'){
									table_reload(rows.length);
								}
								else{
									warningInfo(rtJson.rtMsrg);
								}
							}
						});
					}
				});
			}
		function  viewData(id,is_borrow){
			if(is_borrow==0){
			openDialogResize("<%=contextPath %>/springViews/xm/addOrEditReimbursement.jsp?isShow=1&callback=rtCallBack&id="+id,1000, 800);
			}else{
			openDialogResize("<%=contextPath %>/springViews/xm/addOrEditReimbursementByLoan.jsp?isShow=1&callback=rtCallBack&id="+id,1000, 800);
			}
	
		}

		function rtCallBack(){
			$('#table').datagrid('reload');
		}

	</script>
	<body style="height: 97%">
		<div id="table" data-options="fit:true" ></div>
		<div id="tb" style="padding:3px;height:auto">
			<div style="float:left;">
				<!--<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="deleteRows();">删除</a>-->
				<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="addOrEditReimbursement(0);">新增</a>
			</div>
			<div align="right">
							所属部门：<input  id="dept_id" name="dept_id" class="easyui-combotree" style="width:140px">&nbsp;&nbsp; 
							开始时间：<input id="start_time" name="start_time" class="easyui-datebox" style="width:100px" />&nbsp;&nbsp;&nbsp;结束时间：<input id="end_time" name="end_time" class="easyui-datebox" style="width:100px"/>
							申请人：<input type="text" id="person_id" name="person_id"   style="width:100px">
							项目编号/名称：<input id="searchValue" name="searchValue" style="width:120px" title="项目编号/名称" placeholder="项目编号/名称"/>&nbsp;&nbsp; 
								<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="doSearch();"></a>
			</div>
		</div>
	</body>
</html>
